home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- __revision__ = '$Id: iq.py 651 2006-08-27 19:26:45Z jajcus $'
- __docformat__ = 'restructuredtext en'
- import libxml2
- from pyxmpp.xmlextra import get_node_ns_uri
- from pyxmpp.stanza import Stanza, gen_id
-
- class Iq(Stanza):
- stanza_type = 'iq'
-
- def __init__(self, xmlnode = None, from_jid = None, to_jid = None, stanza_type = None, stanza_id = None, error = None, error_cond = None, stream = None):
- self.xmlnode = None
- if isinstance(xmlnode, Iq):
- pass
- elif isinstance(xmlnode, Stanza):
- raise TypeError, "Couldn't make Iq from other Stanza"
- elif isinstance(xmlnode, libxml2.xmlNode):
- pass
- elif xmlnode is not None:
- raise TypeError, "Couldn't make Iq from %r" % (type(xmlnode),)
- elif not stanza_type:
- raise ValueError, 'type is required for Iq'
- elif not stanza_id and stanza_type in ('get', 'set'):
- stanza_id = gen_id()
-
- if not xmlnode and stanza_type not in ('get', 'set', 'result', 'error'):
- raise ValueError, 'Invalid Iq type: %r' % (stanza_type,)
-
- if xmlnode is None:
- xmlnode = 'iq'
-
- Stanza.__init__(self, xmlnode, from_jid = from_jid, to_jid = to_jid, stanza_type = stanza_type, stanza_id = stanza_id, error = error, error_cond = error_cond, stream = stream)
-
-
- def copy(self):
- return Iq(self)
-
-
- def make_error_response(self, cond):
- if self.get_type() in ('result', 'error'):
- raise ValueError, "Errors may not be generated for 'result' and 'error' iq"
-
- iq = Iq(stanza_type = 'error', from_jid = self.get_to(), to_jid = self.get_from(), stanza_id = self.get_id(), error_cond = cond)
- n = self.get_query()
- if n:
- n = n.copyNode(1)
- iq.xmlnode.children.addPrevSibling(n)
-
- return iq
-
-
- def make_result_response(self):
- if self.get_type() not in ('set', 'get'):
- raise ValueError, "Results may only be generated for 'set' or 'get' iq"
-
- iq = Iq(stanza_type = 'result', from_jid = self.get_to(), to_jid = self.get_from(), stanza_id = self.get_id())
- return iq
-
-
- def new_query(self, ns_uri, name = 'query'):
- return self.set_new_content(ns_uri, name)
-
-
- def get_query(self):
- c = self.xmlnode.children
- while c:
-
- try:
- if c.ns():
- return c
- except libxml2.treeError:
- pass
-
- c = c.next
-
-
- def get_query_ns(self):
- q = self.get_query()
- if q:
- return get_node_ns_uri(q)
- else:
- return None
-
-
-